***Create a data set for incumbency *****************
*****************************************************

/*
This do-file adds information on previous offices (broad understanding of
incumbency) to the 2014 candidate data.

All data can be downloaded from Tribunal Superior Eleitoral.
The data has been downloaded as text-files and been saved as Stata files.
Stata 14 has been used for all operations. 

The file covers elected offices for 2014 candidates to the Federal Elections
in Brazil. It covers the following offices:
- Senator
- Governor
- Federal Deputy
- State Deputy (including Deputies of the Federal District "Diputado Distrital")
- Vereador
- Prefect
- For 2012: Vice Prefect

The files are merged based on the combination of state, name, and birthday
for the period 2006–2012 and  with state, name, and shortname for the period
1998–2006. The id from the TSE was not used for merging since it was not
consistent over years and elections and there were too many duplicates and 
missings on this variable.

2014 candidates might miss information on a previously held office if the 
following occured:
- for the whole period: candidates switched states
- for the whole period: the surname changed or was not consistently written
in the files between elections.
- for 1998-2004: the shortname changed or was not consistently written between
elections.

Lacking data affects less information on offices held shortly before 2014 
than long before since the most recent occurence of cases with duplicates was
retained. Also, cases where both shortnames and names were inconsistent and 
hence merging might have worked particularly badly were corrected by hand. Also,
cases where the entry for the birthay was inconsistent (for 2006–2012) but 
information on state, name and shortname was consistent were corrected by
hand. Entries were corrected based on: https://eleicoes.poder360.com.br/.
Finally, the incumbency variable coded here ignores byelections since this
data was not available in all datasets and including it creates duplicates.

In order to check the quality of the incumbency variables ("office_electedXXXX")
we compared the number of elected candidates for Senate, Chamber of Deputies,
and Governor with the results of the election as published on Wikipedia for each
election separately. Finally, we validated 30 randomly selected entries based on 
a source other than https://eleicoes.poder360.com.br/ (see at the end of the 
do-file).*/

*** 1) Prepare incumbency datasets for each election ***

cd ".../Brazil_candidates_replication/"

***2012 elections***
use cand_2012_appended.dta, clear

* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v7 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v12 id_tse
rename v15 shortname
rename v27 birthday
rename v43 elected

keep year election state number office_nr office name id_tse shortname birthday elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

/* Drop if not the municipal elections (typically suplemental elections where 
the same candidates run, which creates duplicates on the relevant varialbes. */
encode election, gen(election_nr)
drop if election_nr!=6

* Create a variable that measures which office a candidate was elected to
tab elected
encode elected, gen(elected_nr)
keep if elected_nr==3 | elected_nr==4 | elected_nr==5 
rename office office_elected2012

* Format birthday as date
gen double daily = date(birthday, "DMY")
format daily %td
drop birthday
rename daily birthday

* Check duplicates
duplicates report state name birthday

save candidates_for_merge_12.dta, replace


***2010 elections***
use cand_2010_appended.dta, clear

* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v13 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v12 id_tse
rename v15 shortname
rename v27 birthday
rename v43 elected

keep year election state number office_nr office name id_tse shortname birthday elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

* Create a variable that measures which office a candidate was elected to
tab elected
encode elected, gen(elected_nr)
keep if elected_nr==4 | elected_nr==6
rename office office_elected2010
* Numbers for federal (incl. distrital) deputies, senators, and governors are correct

* Format birthday as date
gen double daily = date(birthday, "DM19Y")
format daily %td
drop birthday
rename daily birthday

* Check duplicates
duplicates report state name birthday

save candidates_for_merge_10.dta, replace


***2008 elections***
use cand_2008_appended.dta, clear


* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v7 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v14 id_tse
rename v15 shortname
rename v27 birthday
rename v43 elected

keep year election state number office_nr office name id_tse shortname birthday elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

/* Drop if not the municipal elections (typically suplemental elections where
the same candidates run, which gives duplicates) */
encode election, gen(election_nr)
drop if election_nr!=1

/* Create a variable that measures which office a candidate was elected to
There is no indication on who was elected deputy prefect. */
tab elected
encode elected, gen(elected_nr)
keep if elected_nr==3 | elected_nr==5 
rename office office_elected2008
/* Numbers have been checked with
https://pt.wikipedia.org/wiki/Elei%C3%A7%C3%B5es_municipais_no_Brasil_em_2008 */

* Format birthday as date
gen double daily = date(birthday, "DMY")
format daily %td
drop birthday
rename daily birthday

* Check duplicates
duplicates report state name birthday

save candidates_for_merge_08.dta, replace


***2006 elections***
use cand_2006_appended.dta, clear


* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v12 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v14 id_tse
rename v15 shortname
rename v27 birthday
rename v43 elected

keep year election state number office_nr office name id_tse shortname birthday elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

encode election, gen(election_nr)

* Create a variable that measures which office a candidate was elected to
tab elected
encode elected, gen(elected_nr)
keep if elected_nr==3 | elected_nr==4
rename office office_elected2006
/* Numbers for federal (incl. distrital) deputies, senators, and governors are 
correct. Source: https://en.wikipedia.org/wiki/2006_Brazilian_general_election */

* Format birthday as date
gen double daily = date(birthday, "DMY")
format daily %td
drop birthday
rename daily birthday

* Check duplicates
duplicates report state name birthday

save candidates_for_merge_06.dta, replace


***2004 elections***
use cand_2004_appended.dta, clear


* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v13 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v14 id_tse
rename v15 shortname
rename v43 elected

keep year election state number office_nr office name id_tse shortname elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

encode election, gen(election_nr)

* Create a variable that measures which office a candidate was elected to
tab elected
encode elected, gen(elected_nr)
keep if elected_nr==3 | elected_nr==4
rename office office_elected2004
/* Numbers for prefects compared with Wikepdia. I have 41 elected less, which is
the number of candidatures that were invalidated or taken back after the election.
Source: https://pt.wikipedia.org/wiki/Elei%C3%A7%C3%B5es_municipais_no_Brasil_em_2004 */ 

* There are duplicates on state and name and no more information on birthday.
* This is why I switch to merge with shortname instead of birthday.
duplicates report state name shortname
sort state name shortname
duplicates tag state name shortname, gen(dupl2004)
list state name elected number office_elected2004 if dupl2004>=1, compress
/* There are duplicates because 1) they have the code "eleito" and "média",
2) because they were candidates for prefect and vereador at the same time 
or 3) they are full duplicates. I drop the "Vereador" or first instance of them. */
drop if elected_nr==4 & dupl2004==1
* Drop the "vereador" duplicate because prefect is a more prestigious office.
drop if office_elected2004=="VEREADOR" & name=="JOAO DE OLIVEIRA"
drop if office_elected2004=="VEREADOR" & name=="JOSE FERNANDES DA SILVA"
drop if name=="VALTER GOMES" & number==25622
drop if name=="JOSE MARIA DE OLIVEIRA" & number==15678
drop if name=="JOSE CARLOS DE OLIVEIRA" & number==13456

* No duplicates left
drop dupl2004

* There are a few missing id_tse, which is why the variable is string
destring id_tse, replace force

save candidates_for_merge_04.dta, replace


***2002 elections***
use cand_2002_appended.dta, clear


* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v12 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v14 id_tse
rename v15 shortname
rename v43 elected

keep year election state number office_nr office name id_tse shortname elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

encode election, gen(election_nr)

* Create a variable that measures which office a candidate was elected to
tab elected
encode elected, gen(elected_nr)
keep if elected_nr==3 | elected_nr==4 
rename office office_elected2002
/* Numbers for senators and governors are correct, one federal deuputy too many
because of wrong value in source */
drop if name=="MARCUS SAVIUS TEIXEIRA SOUSA" & stat=="CE"

duplicates report state name shortname

* There are a lot of missing id_tse, which is why the variable is string
destring id_tse, replace force

save candidates_for_merge_02.dta, replace


***2000 elections***
use cand_2000_appended.dta, clear

* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v13 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v14 id_tse
rename v15 shortname
rename v43 elected

keep year election state number office_nr office name id_tse shortname elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

encode election, gen(election_nr)

* Create a variable that measures which office a candidate was elected to
tab elected
encode elected, gen(elected_nr)
keep if elected_nr==2 | elected_nr==3 | elected_nr==4
rename office office_elected2000
/* Checked prefects. I have one more than indicated on Wikipedia:
https://pt.wikipedia.org/wiki/Elei%C3%A7%C3%B5es_municipais_no_Brasil_em_2000 */

duplicates report state name shortname
/* I have 23 duplicates. They seem to be due to very common names. 
I cannot resolve them. Hence, I drop here the first duplicate. But if they 
remain in the dataset they have to be corrected after merging. */
duplicates tag state name shortname, gen(dupl00)
list state name shortname if dupl00>0, compress
duplicates drop state name shortname, force

* There are a few missing id_tse, which is why the variable is string
destring id_tse, replace force

save candidates_for_merge_00.dta, replace


***1998 elections***
use cand_1998_appended.dta, clear

* Keep and rename the relevant variables
rename v3 year
rename v5 election
rename v6 state
rename v12 number
rename v9 office_nr
rename v10 office
rename v11 name
rename v14 id_tse
rename v15 shortname
rename v43 elected

keep year election state number office_nr office name id_tse shortname elected

cleanchars _all, in(Á Ã Â Ç É Ê Í Ô Ó Õ Ú) out(A A A C E E I O O O U) vval

encode election, gen(election_nr)

* Create a variable that measures which office a candidate was elected to
tab elected
encode elected, gen(elected_nr)
* Keep also those withdrawn after the election to drop its duplicates
keep if elected_nr==2 | elected_nr==3
rename office office_elected1998
/* I have 7 DFs too many. There are seven without id_tse code. Checked for one
* case in Espiritu Santo that these candidates were really not elected. */
drop if id_tse=="#NULO#" & office_elected1998=="DEPUTADO FEDERAL"
* Now numbers are correct.
tab office_elected1998

duplicates report state name shortname

*There are a lot of missing id_tse, which is why the variable is string
destring id_tse, replace force

save candidates_for_merge_98.dta, replace


*** 2) Merge the incumbency datasets for each election ***

use candidates_for_merge_12.dta, clear

* Merge 2012 with 2010
merge 1:1 state name birthday using candidates_for_merge_10.dta
rename _merge merge_10_12
save candidates_for_merge_10_12.dta, replace

* Merge 2010/2012 with 2008
merge 1:1 state name birthday using candidates_for_merge_08.dta
rename _merge merge_08_10_12
save candidates_for_merge_08_10_12.dta, replace

* Merge 2008/2010/2012 with 2006
merge 1:1 state name birthday using candidates_for_merge_06.dta
rename _merge merge_06_08_10_12
*Everything fine:
tab office_elected2006
* Switch now to merge with shortname instead of birthday. Check for duplicates:
gsort - year state name shortname
duplicates report state name shortname
/* Duplicates on state-name-shortname combinations are or due to 1) mistakes
in the birthday value in the dataset or 2) when the duplicates are real due
to very common names. Tag these duplicates and resolve those of them that 
are in the 2014 candidate dataset after the final merge case-by-case. Sort
descending so that you keep the more recent ones. */
duplicates tag state name shortname, gen(dupl_06_08_10_12)
*list year state name birthday if dupl_06_08_10_12==1
duplicates drop state name shortname, force
save candidates_for_merge_06_08_10_12.dta, replace

* Merge 2006/2008/2010/2012 with 2004
merge 1:1 state name shortname using candidates_for_merge_04.dta
rename _merge merge_04_06_08_10_12
save candidates_for_merge_04_06_08_10_12.dta, replace

* Merge 2004/2006/2008/2010/2012 with 2002
merge 1:1 state name shortname using candidates_for_merge_02.dta
rename _merge merge_02_04_06_08_10_12
save candidates_for_merge_02_04_06_08_10_12.dta, replace

* Merge 2002/2004/2006/2008/2010/2012 with 2000
merge 1:1 state name shortname using candidates_for_merge_00.dta
rename _merge merge_00_02_04_06_08_10_12
save candidates_for_merge_00_02_04_06_08_10_12.dta, replace

* Merge 2000/2002/2004/2006/2008/2010/2012 with 1998
merge 1:1 state name shortname using candidates_for_merge_98.dta
rename _merge merge_98_00_02_04_06_08_10_12

/*A main problem could be that candidates changed shortnames. These would be
duplicates on state-name combinations. Tag them and resolve those
in the 2014 candidate dataset after merging*/
duplicates report state name
duplicates tag state name, gen(duplsn)
gen state_name_dupl=1 if duplsn>=1
drop duplsn

/*Another problem can be changes in the spelling of the names (special characters!)
We should see most of them in state-shortname duplicates*/
duplicates report state shortname
duplicates tag state shortname, gen(duplss)
gen state_shortname_dupl=1 if duplss>=1
drop duplss

* Keep only the variables that could be merged
keep state name shortname birthday year office_elected1998 office_elected2000 /*
*/ office_elected2002 office_elected2004 office_elected2006 office_elected2008 /*
*/ office_elected2010 office_elected2012 id_tse dupl_06_08_10_12 /*
*/ state_name_dupl state_shortname_dupl dupl00

save incumbency_for_merge.dta, replace

***Check plausibility of numbers

tab office_elected1998
tab office_elected2000
tab office_elected2002
tab office_elected2004
tab office_elected2006
* 11 cases for DF and 1 for Governador missing because of dropped duplicates
tab office_elected2008
* Less cases than without merge because of dropped duplicates
tab office_elected2010
* 4 DF missing because of dropped duplicates
tab office_elected2012

* Between general elections
tab2 office_elected1998 office_elected2002
tab2 office_elected2002 office_elected2006
tab2 office_elected2006 office_elected2010

* Between midterm and local elections
tab2 office_elected2000 office_elected2004
tab2 office_elected2004 office_elected2008
tab2 office_elected2008 office_elected2012


*** 3) Merge with 2014 dataset on candidate information, vote and expenditure ***

* Merge with unique state shortname combinations
use incumbency_for_merge.dta, clear

* Drop all but the first case that has duplicates on this combination
gsort - year state shortname
duplicates drop state shortname, force
* I lose cases from 2012 because of second and more occurrences of duplicates

merge 1:1 state shortname using cand_2014_campexp_vote.dta, force

* Drop all that could not be merged
drop if _merge!=3
drop _merge

save incumbency_merged_state_shortname.dta, replace

/*Prepare the campexp_vote data for merge with state-name: There are two Sonia
Maria Ferreiras. They have to be dropped (they are unique with state-shortname)*/

use cand_2014_campexp_vote.dta, clear
drop if name=="SONIA MARIA FERREIRA" & state=="MG"
save cand_2014_campexp_vote_merge.dta, replace

* Merge also with unique state name combinations
use incumbency_for_merge.dta, clear

* Drop all but the first case that has duplicates on this combination
gsort - year state name
duplicates drop state name, force

merge 1:1 state name using cand_2014_campexp_vote_merge.dta, force

* Drop all from incumbency data that could not be merged
drop if _merge==1

* Append the previously merged cases
append using incumbency_merged_state_shortname.dta

/* Drop first duplicates of those that have been merged at least twice.*/
duplicates report id_2014
duplicates drop id_2014, force

* No cases that were duplicates in 2000
tab dupl00

/* Those cases that have state-name and state-shortname duplicates are most
likely to lack information. Resolve them by hand. */
tab state_shortname_dupl state_name_dupl, missing
/* Check for missing information: list state name office_elected1998 
office_elected2000 office_elected2002 office_elected2004 office_elected2006 
office_elected2008 office_elected2010 office_elected2012 if state_name_dupl==1. */
replace office_elected1998="DEPUTADO ESTADUAL" if state=="AC" & name=="JOSE VIEIRA DE FARIAS"
replace office_elected1998="DEPUTADO FEDERAL" if state=="AL" & name=="GIVALDO DE SA GOUVEIA CARIMBAO"
replace office_elected1998="DEPUTADO FEDERAL" if state=="AP" & name=="EDUARDO SEABRA DA COSTA"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="AP" & name=="JANETE MARIA GOES CAPIBERIBE"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="BA" & name=="JOSE NUNES SOARES"
replace office_elected1998="DEPUTADO FEDERAL" if state=="CE" & name=="MORONI BING TORGAN"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="GO" & name=="CELIO ANTONIO DA SILVEIRA"
replace office_elected1998="DEPUTADO FEDERAL" if state=="MA" & name=="JOAO CASTELO RIBEIRO GONCALVES"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="MG" & name=="ADELMO CARNEIRO LEAO"
replace office_elected1998="DEPUTADO FEDERAL" if state=="MG" & name=="JAIME MARTINS FILHO"
replace office_elected1998="DEPUTADO FEDERAL" if state=="MG" & name=="JOSE SARAIVA FELIPE"
replace office_elected1998="DEPUTADO FEDERAL" if state=="MG" & name=="SILAS BRASILEIRO"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="MT" & name=="ELIENE JOSE DE LIMA"
replace office_elected1998="DEPUTADO FEDERAL" if state=="PA" & name=="ELCIONE THEREZINHA ZAHLUTH BARBALHO"
replace office_elected1998="DEPUTADO FEDERAL" if state=="PE" & name=="CARLOS EDUARDO CINTRA DA COSTA PEREIRA"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="PE" & name=="LUCIANA BARBOSA DE OLIVEIRA SANTOS"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="PE" & name=="LUCIANA BARBOSA DE OLIVEIRA SANTOS"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="PR" & name=="ANGELO CARLOS VANHONI"
replace office_elected1998="DEPUTADO FEDERAL" if state=="PR" & name=="LUIZ CARLOS JORGE HAULY"
replace office_elected1998="DEPUTADO FEDERAL" if state=="PR" & name=="RAFAEL VALDOMIRO GRECA DE MACEDO"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="PR" & name=="VALDIR LUIZ ROSSONI"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="RJ" & name=="ANDREIA ALMEIDA ZITO DOS SANTOS"
replace office_elected1998="DEPUTADO FEDERAL" if state=="RJ" & name=="JORGE RICARDO BITTAR"
replace office_elected1998="DEPUTADO FEDERAL" if state=="RJ" & name=="PAULO CESAR BALTAZAR DA NOBREGA"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="RN" & name=="ANTONIO JACOME DE LIMA JUNIOR"
replace office_elected1998="DEPUTADO FEDERAL" if state=="RO" & name=="AGNALDO MUNIZ"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="RR" & name=="EDIO VIEIRA LOPES"
replace office_elected1998="DEPUTADO FEDERAL" if state=="RS" & name=="FERNANDO STEPHAN MARRONI"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="RS" & name=="GIOVANI CHERINI"
replace office_elected1998="DEPUTADO FEDERAL" if state=="SC" & name=="EDSON BEZ DE OLIVEIRA"
replace office_elected1998="DEPUTADO FEDERAL" if state=="SE" & name=="ADELSON BARRETO DOS SANTOS"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="SP" & name=="ADRIANO ELI CORREA"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="SP" & name=="ANTONIO DUARTE NOGUEIRA JUNIOR"
replace office_elected1998="DEPUTADO FEDERAL" if state=="SP" & name=="NELSON MARQUEZELLI"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="TO" & name=="JOAO OLIVEIRA DE SOUSA"
replace office_elected2000="VEREADOR" if state=="AL" & name=="JOSE JULIO DE ALMEIDA FILHO"
replace office_elected2000="VEREADOR" if state=="AL" & name=="MAURICIO QUINTELLA MALTA LESSA"
replace office_elected2000="PREFEITO" if state=="AM" & name=="ALFREDO PEREIRA DO NASCIMENTO"
replace office_elected2000="VEREADOR" if state=="AM" & name=="ARTHUR VIRGILIO DO CARMO RIBEIRO BISNETO"
replace office_elected2000="VEREADOR" if state=="BA" & name=="EMILIANO JOSE DA SILVA FILHO"
replace office_elected2000="VEREADOR" if state=="BA" & name=="FERNANDO DANTAS TORRES"
replace office_elected2000="VEREADOR" if state=="BA" & name=="HUMBERTO LOPES CEDRAZ"
replace office_elected2000="VEREADOR" if state=="BA" & name=="JOAO LUIZ SILVA SANTOS"
replace office_elected2000="VEREADOR" if state=="BA" & name=="MAURICIO GONCALVES TRINDADE"
replace office_elected2000="VEREADOR" if state=="BA" & name=="ROBERIO ALVES NEVES"
replace office_elected2000="PREFEITO" if state=="CE" & name=="EUGENIO RABELO"
replace office_elected2000="VEREADOR" if state=="CE" & name=="JAZIEL PEREIRA DE SOUSA"
replace office_elected2000="VEREADOR" if state=="CE" & name=="JOSE AIRTON FELIX CIRILO DA SILVA"
replace office_elected2000="VEREADOR" if state=="ES" & name=="TADEU JOSE DE SA NASCIMENTO"
replace office_elected2000="VEREADOR" if state=="GO" & name=="FRANCISCA DE ASSIS CANDIDA"
replace office_elected2000="VEREADOR" if state=="GO" & name=="MAGDA MOFATTO HON"
replace office_elected2000="VEREADOR" if state=="MG" & name=="DIMAS FABIANO TOLEDO JUNIOR"
replace office_elected2000="DEPUTADO ESTADUAL" if state=="MG" & name=="DIMAS FABIANO TOLEDO JUNIOR"
replace office_elected2000="VEREADOR" if state=="MG" & name=="EDNA SARMENTO BARROS"
replace office_elected2000="VEREADOR" if state=="MG" & name=="FABIANO COSTA DINIZ"
replace office_elected2000="VEREADOR" if state=="MG" & name=="JANDER MUNIZ FILARETTI"
replace office_elected2000="VEREADOR" if state=="MG" & name=="JOSE DE ARAUJO GUEDES"
replace office_elected2000="PREFEITO" if state=="MG" & name=="JOSE HUMBERTO SOARES"
replace office_elected2000="VEREADOR" if state=="MG" & name=="JUAREZ JOSE MUNIZ"
replace office_elected2000="VEREADOR" if state=="MG" & name=="MAURILIO BARBOSA DA SILVA"
replace office_elected2000="VEREADOR" if state=="MG" & name=="ROMULO VICTOR PINHEIRO VENEROSO"
replace office_elected2000="VEREADOR" if state=="MG" & name=="RONALDO BRAGA"
replace office_elected2000="VEREADOR" if state=="MG" & name=="SERGIO LUCIO DE ALMEIDA"
replace office_elected2000="VEREADOR" if state=="MS" & name=="ODAIR JOSE BORTOLOTI"
replace office_elected2000="VEREADOR" if state=="MT" & name=="BENEDITO FRANCISCO CURVO"
replace office_elected2000="PREFEITO" if state=="MT" & name=="EZEQUIEL ANGELO FONSECA"
replace office_elected2000="VEREADOR" if state=="PA" & name=="ANA JULIA DE VASCONCELOS CAREPA"
replace office_elected2000="VEREADOR" if state=="PA" & name=="ARNALDO JORDY FIGUEIREDO"
replace office_elected2000="VEREADOR" if state=="PA" & name=="JOAQUIM PASSARINHO PINTO DE SOUZA PORTO"
replace office_elected2000="VEREADOR" if state=="PA" & name=="RAIMUNDO VALRY DE MORAIS"
replace office_elected2000="VEREADOR" if state=="PA" & name=="RAUL BATISTA DE SOUZA"
replace office_elected2000="PREFEITO" if state=="PB" & name=="BENJAMIN GOMES MARANHAO NETO"
replace office_elected2000="VEREADOR" if state=="PB" & name=="JOSE FREIRE DA COSTA"
replace office_elected2000="PREFEITO" if state=="PB" & name=="MANOEL ALVES DA SILVA JUNIOR"
replace office_elected2000="VEREADOR" if state=="PB" & name=="VENEZIANO VITAL DO REGO SEGUNDO NETO"
replace office_elected2000="PREFEITO" if state=="PE" & name=="ADALBERTO CAVALCANTI RODRIGUES"
replace office_elected2000="VEREADOR" if state=="PE" & name=="NUNES RAFAEL MENDES COELHO"
replace office_elected2000="VEREADOR" if state=="PE" & name=="ROGERIO LIMA DE LUCCA"
replace office_elected2000="VEREADOR" if state=="PR" & name=="ANTENOR GOMES DE LIMA"
replace office_elected2000="VEREADOR" if state=="PR" & name=="CLAIR DA FLORA MARTINS"
replace office_elected2000="VEREADOR" if state=="PR" & name=="DILTO VITORASSI"
replace office_elected2000="VEREADOR" if state=="PR" & name=="EDMAR DE SOUZA ARRUDA"
replace office_elected2000="VEREADOR" if state=="PR" & name=="EDUARDO FRANCISCO COSTA DE OLIVEIRA"
replace office_elected2000="VEREADOR" if state=="PR" & name=="JOSE APARECIDO GOTARDO"
replace office_elected2000="VEREADOR" if state=="PR" & name=="JOSE CARLOS CAMARGO"
replace office_elected2000="VEREADOR" if state=="PR" & name=="ODAIR DO PRADO"
replace office_elected2000="VEREADOR" if state=="PR" & name=="OSMAR STUART BERTOLDI"
replace office_elected2000="VEREADOR" if state=="PR" & name=="PAULO SALAMUNI"
replace office_elected2000="VEREADOR" if state=="PR" & name=="SERGIO PAULO DE OLIVEIRA"
replace office_elected2000="VEREADOR" if state=="PR" & name=="VALDIR CARLOS FERNANDES"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="AMERICA TEREZA NASCIMENTO DA SILVA"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="DILSON MALHEIROS DRUMOND"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="FERNANDO GOMES CID"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="JORGE HENRIQUE DA COSTA NUNES"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="JORGE MAROTTE CORREA"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="JOSE VALDEZIR PEREIRA DE LIMA"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="LUIZ CARLOS RAMOS"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="MARCELO AMARAL CARNEIRO"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="MARIA APARECIDA PANISSET"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="NELSON NAHIM MATHEUS DE OLIVEIRA"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="OTAVIO SANTOS SILVA LEITE"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="PAULO CESAR DA GUIA ALMEIDA"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="PAULO EDUARDO GOMES"
replace office_elected2000="VEREADOR" if state=="RJ" & name=="ROSANGELA DE SOUZA GOMES"
replace office_elected2000="VEREADOR" if state=="RN" & name=="HUGO MANSO JUNIOR"
replace office_elected2000="VEREADOR" if state=="RN" & name=="RAIMUNDO ANTUNES DE MIRANDA"
replace office_elected2000="VEREADOR" if state=="RO" & name=="FLAVIO HONORIO DE LEMOS"
replace office_elected2000="VEREADOR" if state=="RO" & name=="LUIZ CLAUDIO PEREIRA ALVES"
replace office_elected2000="VEREADOR" if state=="RO" & name=="ROSARIA HELENA DE OLIVEIRA LIMA"
replace office_elected2000="VEREADOR" if state=="RS" & name=="ALEXANDRE RUBIO ROSO"
replace office_elected2000="VEREADOR" if state=="RS" & name=="ANTONIO ARILENE PEREIRA"
replace office_elected2000="VEREADOR" if state=="RS" & name=="CLAUDIO CASTANHEIRA DIAZ"
replace office_elected2000="VEREADOR" if state=="RS" & name=="ELTON SEBASTIAO ROSPIDE DA SILVA"
replace office_elected2000="VEREADOR" if state=="RS" & name=="JAIR RIZZO FERREIRA"
replace office_elected2000="VEREADOR" if state=="RS" & name=="LUIZ MIGUEL SCHEIS"
replace office_elected2000="VEREADOR" if state=="RS" & name=="MARCIO DELLA VALLE BIOLCHI"
replace office_elected2000="VEREADOR" if state=="RS" & name=="RONALDO NOGUEIRA DE OLIVEIRA"
replace office_elected2000="VEREADOR" if state=="RS" & name=="SERGIO VIEIRA DA MOTTA"
replace office_elected2000="DEPUTADO ESTADUAL" if state=="RS" & name=="SERGIO VIEIRA DA MOTTA"
replace office_elected2000="VEREADOR" if state=="SC" & name=="FABRICIO JOSE SATIRO DE OLIVEIRA"
replace office_elected2000="VEREADOR" if state=="SC" & name=="JOAO BATISTA NUNES"
replace office_elected2000="VEREADOR" if state=="SC" & name=="JOSE PAULO SERAFIM"
replace office_elected2000="PREFEITO" if state=="SC" & name=="MAURO MARIANI"
replace office_elected2000="VEREADOR" if state=="SP" & name=="ADEMIR ALBANO LOPES"
replace office_elected2000="VEREADOR" if state=="SP" & name=="ALBERTO BETAO PEREIRA JUSTINO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="AMELIA NAOMI OMURA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="ANTONIO DE JESUS ROCHA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="ANTONIO GOULART DOS REIS"
replace office_elected2000="VEREADOR" if state=="SP" & name=="BALBINA DE OLIVEIRA DE PAULA SANTOS"
replace office_elected2000="VEREADOR" if state=="SP" & name=="DEVANIR RIBEIRO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="DINIZ LOPES DOS SANTOS"
replace office_elected2000="VEREADOR" if state=="SP" & name=="EDNA SANDRA MARTINS"
replace office_elected2000="VEREADOR" if state=="SP" & name=="ELISEU GABRIEL DE PIERI"
replace office_elected2000="DEPUTADO ESTADUAL" if state=="SP" & name=="ELISEU GABRIEL DE PIERI"
replace office_elected2000="VEREADOR" if state=="SP" & name=="FERNANDO BISPO DA SILVA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="FRANCISCO EDUARDO ANICETO ROSSI"
replace office_elected2000="VEREADOR" if state=="SP" & name=="GILBERTO COSTA MARQUES"
replace office_elected2000="VEREADOR" if state=="SP" & name=="GILBERTO LOURENCO MARSON"
replace office_elected2000="VEREADOR" if state=="SP" & name=="HAVANIR TAVARES DE ALMEIDA NIMTZ"
replace office_elected2000="VEREADOR" if state=="SP" & name=="JORGE ABISSAMRA"
replace office_elected2000="PREFEITO" if state=="SP" & name=="JORGE ABISSAMRA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="JORGE MARTINS SALGADO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="JOSE MENTOR GUILHERME DE MELLO NETTO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="JOSE OLIMPIO SILVEIRA MORAES"
replace office_elected2000="PREFEITO" if state=="SP" & name=="JUNJI ABE"
replace office_elected2000="VEREADOR" if state=="SP" & name=="LUCIO MARTINS DE FREITAS"
replace office_elected2000="VEREADOR" if state=="SP" & name=="LUIZ CARLOS DONEGA NETO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="LUIZ FELIPE BALEIA TENUTO ROSSI"
replace office_elected2000="VEREADOR" if state=="SP" & name=="MARCELO JOSE ORTEGA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="MARCOS VINHA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="MARIA APARECIDA FERREIRA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="MIGUEL LOMBARDI"
replace office_elected2000="VEREADOR" if state=="SP" & name=="NELSON GONCALVES PINTO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="NEUZA DAS GRACAS SOARES DA SILVA"
replace office_elected2000="PREFEITO" if state=="SP" & name=="NEWTON LIMA NETO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="PAULO HUMBERTO LACERDA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="PAULO JESUS FRANGE"
replace office_elected2000="VEREADOR" if state=="SP" & name=="PEDRO SERAFIM JUNIOR"
replace office_elected2000="VEREADOR" if state=="SP" & name=="RUBENS BENEDITO FERNANDES"
replace office_elected2000="PREFEITO" if state=="SP" & name=="SAMUEL MOREIRA DA SILVA JUNIOR"
replace office_elected2000="VEREADOR" if state=="SP" & name=="SEBASTIAO PEREIRA DOS SANTOS"
replace office_elected2000="VEREADOR" if state=="SP" & name=="SERGIO FERNANDES FILHO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="VICENTE CANDIDO DA SILVA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="WILLIAM BOSS WOO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="WILSON DE SOUZA COELHO"
replace office_elected2000="VEREADOR" if state=="TO" & name=="RAIMUNDO COIMBRA JUNIOR"
replace office_elected2002="DEPUTADO FEDERAL" if state=="AM" & name=="PAUDERNEY TOMAZ AVELINO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="BA" & name=="ALBERTO FABIO FERREIRA DE SANTANA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="BA" & name=="CLAUDIO CAJADO SAMPAIO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="BA" & name=="DANIEL GOMES DE ALMEIDA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="BA" & name=="JUTAHY MAGALHAES JUNIOR"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="BA" & name=="MARCIO CARLOS MARINHO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="CE" & name=="ANIBAL FERREIRA GOMES"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="CE" & name=="FRANCISCO LOPES DA SILVA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="CE" & name=="INACIO FRANCISCO DE ASSIS NUNES ARRUDA"
replace office_elected2002="DEPUTADO DISTRITAL" if state=="DF" & name=="AUGUSTO SILVEIRA DE CARVALHO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="ES" & name=="JOSE CARLOS ELIAS"
replace office_elected2002="VEREADOR" if state=="ES" & name=="VANDERSON ALONSO LEITE"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MG" & name=="ADELMO CARNEIRO LEAO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="MG" & name=="BONIFACIO JOSE TAMM DE ANDRADA"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MG" & name=="JOAO CARLOS SIQUEIRA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="MG" & name=="ODAIR JOSE DA CUNHA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="MS" & name=="ANTONIO FERREIRA DA CRUZ FILHO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MS" & name=="DAGOBERTO NOGUEIRA FILHO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MT" & name=="ELIENE JOSE DE LIMA"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MT" & name=="HERMINIO BARRETO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="PB" & name=="AGUINALDO VELLOSO BORGES RIBEIRO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PB" & name=="JOSE WELLINGTON ROBERTO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PB" & name=="LUIZ ALBUQUERQUE COUTO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="PB" & name=="MANOEL ALVES DA SILVA JUNIOR"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PE" & name=="ANDRE CARLOS ALVES DE PAULA FILHO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="PE" & name=="SEBASTIAO IGNACIO DE OLIVEIRA JUNIOR"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PI" & name=="ATILA FREITAS LIRA"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="PR" & name=="ANGELO CARLOS VANHONI"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PR" & name=="ASSIS MIGUEL DO COUTO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PR" & name=="DILCEU JOAO SPERAFICO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PR" & name=="HERMES PARCIANELLO"
replace office_elected2002="PREFEITO" if state=="PR" & name=="JOSE CARLOS BECKER DE OLIVEIRA E SILVA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="PR" & name=="OSMAR JOSE SERRAGLIO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="PR" & name=="VALDIR LUIZ ROSSONI"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="RJ" & name=="JORGE MAROTTE CORREA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="RJ" & name=="LEONARDO CARNEIRO MONTEIRO PICCIANI"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="RS" & name=="ALEXANDRE RUBIO ROSO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="RS" & name=="JERONIMO PIZZOLOTTO GOERGEN"
replace office_elected2002="DEPUTADO FEDERAL" if state=="RS" & name=="ONYX DORNELLES LORENZONI"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="RS" & name=="RONALDO MIRO ZULKE"
replace office_elected2002="DEPUTADO FEDERAL" if state=="SC" & name=="JORGE CATARINO LEONARDELI BOEIRA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="SP" & name=="ANTONIO ADOLPHO LOBBE NETO"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="SP" & name=="BENEDITO ROBERTO ALVES FERREIRA"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="SP" & name=="JOSE RICARDO ALVARENGA TRIPOLI"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="SP" & name=="LUIZ FELIPE BALEIA TENUTO ROSSI"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="SP" & name=="PAULO CESAR NEME"
replace office_elected2002="PREFEITO" if state=="SP" & name=="PAULO CESAR NEME"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="SP" & name=="PEDRO SERAFIM JUNIOR"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="SP" & name=="ROBERVAL CONTE LOPES LIMA"
replace office_elected2004="PREFEITO" if state=="BA" & name=="JOAO CARLOS BACELAR BATISTA"
replace office_elected2004="VEREADOR" if state=="BA" & name=="JOAO LUIZ SILVA SANTOS"
replace office_elected2004="VEREADOR" if state=="BA" & name=="ODIOSVALDO BOMFIM VIGAS"
replace office_elected2004="VEREADOR" if state=="BA" & name=="RAMON DE SENA SOUZA"
replace office_elected2004="VEREADOR" if state=="CE" & name=="JOSE AIRTON FELIX CIRILO DA SILVA"
replace office_elected2004="PREFEITO" if state=="ES" & name=="NORMA AYUB ALVES"
replace office_elected2004="VEREADOR" if state=="GO" & name=="FABIO FERNANDES DE SOUSA"
replace office_elected2004="PREFEITO" if state=="MA" & name=="RAIMUNDO NONATO LISBOA"
replace office_elected2004="VEREADOR" if state=="MG" & name=="MIGUEL CORREA DA SILVA JUNIOR"
replace office_elected2004="VEREADOR" if state=="MS" & name=="ODAIR JOSE BORTOLOTI"
replace office_elected2004="VEREADOR" if state=="MT" & name=="ISMAILI DE OLIVEIRA DONASSAN"
replace office_elected2004="VEREADOR" if state=="MT" & name=="VALTENIR LUIZ PEREIRA"
replace office_elected2004="VEREADOR" if state=="PA" & name=="CARLOS DO SOCORRO GUERREIRO VAZ"
replace office_elected2004="VEREADOR" if state=="PA" & name=="CARLOS EDUARDO CARDOSO MARTINS"
replace office_elected2004="PREFEITO" if state=="PA" & name=="JOSE WALDOLI FILGUEIRA VALENTE"
replace office_elected2004="PREFEITO" if state=="PE" & name=="ADALBERTO CAVALCANTI RODRIGUES"
replace office_elected2004="VEREADOR" if state=="PE" & name=="JOSENILDO SINESIO DA SILVA"
replace office_elected2004="PREFEITO" if state=="PE" & name=="LUCIANA BARBOSA DE OLIVEIRA SANTOS"
replace office_elected2004="VEREADOR" if state=="PE" & name=="ZACARIAS VILHARBA"
replace office_elected2004="PREFEITO" if state=="PR" & name=="EFRAIM BUENO DE MORAES"
replace office_elected2004="VEREADOR" if state=="RJ" & name=="DILSON MALHEIROS DRUMOND"
replace office_elected2004="VEREADOR" if state=="RJ" & name=="JORGE MAROTTE CORREA"
replace office_elected2004="VEREADOR" if state=="RJ" & name=="LUIZ CARLOS RAMOS"
replace office_elected2004="VEREADOR" if state=="RS" & name=="ANABEL LORENZI"
replace office_elected2004="PREFEITO" if state=="RS" & name=="GIOVANI BATISTA FELTES"
replace office_elected2004="PREFEITO" if state=="RS" & name=="JOSE ALBERTO FOGACA DE MEDEIROS"
replace office_elected2004="VEREADOR" if state=="RS" & name=="JULIO CESAR PEREIRA DA SILVA"
replace office_elected2004="VEREADOR" if state=="RS" & name=="OVIDIO DA SILVA MAYER"
replace office_elected2004="VEREADOR" if state=="RS" & name=="VALDECIR VARGAS DE ALMEIDA"
replace office_elected2004="VEREADOR" if state=="SC" & name=="JOVINO CARDOSO NETO"
replace office_elected2004="VEREADOR" if state=="SE" & name=="JOSE IRAN BARBOSA FILHO"
replace office_elected2004="VEREADOR" if state=="SP" & name=="ADEMIR ALBANO LOPES"
replace office_elected2004="VEREADOR" if state=="SP" & name=="ANTONIO GOULART DOS REIS"
replace office_elected2004="PREFEITO" if state=="SP" & name=="CARLOS ALBERTO DE SOUZA"
replace office_elected2004="VEREADOR" if state=="SP" & name=="EDNA SANDRA MARTINS"
replace office_elected2004="VEREADOR" if state=="SP" & name=="GERVASIO APARECIDO DA SILVA"
replace office_elected2004="VEREADOR" if state=="SP" & name=="JOSE APRIGIO DA SILVA"
replace office_elected2004="PREFEITO" if state=="SP" & name=="JUNJI ABE"
replace office_elected2004="VEREADOR" if state=="SP" & name=="NELSON GONCALVES PINTO"
replace office_elected2004="PREFEITO" if state=="SP" & name=="NEWTON LIMA NETO"
replace office_elected2004="VEREADOR" if state=="SP" & name=="RICARDO YOSHIO"
replace office_elected2004="VEREADOR" if state=="SP" & name=="SEBASTIAO PEREIRA DOS SANTOS"
replace office_elected2004="VEREADOR" if state=="SP" & name=="WAINES MOREIRA ALVES"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="BA" & name=="JOSE NUNES SOARES"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="CE" & name=="FRANCISCO LOPES DA SILVA"
replace office_elected2006="DEPUTADO FEDERAL" if state=="MG" & name=="JUAREZ JOSE MUNIZ"
replace office_elected2006="DEPUTADO FEDERAL" if state=="PA" & name=="RAUL BATISTA DE SOUZA"
replace office_elected2006="DEPUTADO FEDERAL" if state=="PB" & name=="BENJAMIN GOMES MARANHAO NETO"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="SP" & name=="ANTONIO GOMES DA SILVA"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="SP" & name=="WILSON DE SOUZA COELHO"
replace office_elected2008="VEREADOR" if state=="AL" & name=="SEVERINO CORREIA CAVALCANTE"
replace office_elected2008="VEREADOR" if state=="MA" & name=="LEONARDO SARMENTO PIRES DE SA"
replace office_elected2008="VEREADOR" if state=="RJ" & name=="GEISO PEREIRA TURQUES"
replace office_elected2008="VEREADOR" if state=="RS" & name=="ELTON SEBASTIAO ROSPIDE DA SILVA"
replace office_elected2008="PREFEITO" if state=="SP" & name=="CARLOS ALBERTO DE SOUZA"
replace office_elected2008="VEREADOR" if state=="SP" & name=="ROBERVAL SAKAI BASTOS PINTO"
replace office_elected2010="DEPUTADO FEDERAL" if state=="AL" & name=="GIVALDO DE SA GOUVEIA CARIMBAO"
replace office_elected2010="DEPUTADO FEDERAL" if state=="CE" & name=="FRANCISCO LOPES DA SILVA"
replace office_elected2010="DEPUTADO FEDERAL" if state=="CE" & name=="FRANCISCO LOPES DA SILVA"
replace office_elected2010="DEPUTADO ESTADUAL" if state=="CE" & name=="JAZIEL PEREIRA DE SOUSA"
replace office_elected2010="DEPUTADO ESTADUAL" if state=="MG" & name=="JOSE CARLOS DE SOUZA"
replace office_elected2010="DEPUTADO FEDERAL" if state=="PB" & name=="BENJAMIN GOMES MARANHAO NETO"
replace office_elected2010="DEPUTADO FEDERAL" if state=="PE" & name=="MARCOS ANTONIO DA SILVA"
replace office_elected2010="VEREADOR" if state=="RJ" & name=="JORGE MAROTTE CORREA"
replace office_elected2010="DEPUTADO FEDERAL" if state=="RJ" & name=="PAULO CESAR BALTAZAR DA NOBREGA"
replace office_elected2010="DEPUTADO FEDERAL" if state=="RJ" & name=="PAULO EDUARDO GOMES"
replace office_elected2010="DEPUTADO FEDERAL" if state=="RJ" & name=="SEBASTIAO FERREIRA DA SILVA"
replace office_elected2010="DEPUTADO ESTADUAL" if state=="SP" & name=="DINIZ LOPES DOS SANTOS"
replace office_elected2012="VEREADOR" if state=="BA" & name=="ODIOSVALDO BOMFIM VIGAS"



* Check state-shortname duplicates
/* Check for missing information: list state name office_elected1998 
office_elected2000 office_elected2002 office_elected2004 office_elected2006 
office_elected2008 office_elected2010 office_elected2012 if state_shortname_dupl==1*/
replace office_elected1998="DEPUTADO ESTADUAL" if state=="AL" & name=="MARCOS ANTONIO FERREIRA NUNES"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="AL" & name=="MARIA FATIMA GALINA FORTES FERREIRA SANTIAGO"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="MA" & name=="DEOCLIDES ANTONIO SANTOS NETO MACEDO"
replace office_elected1998="DEPUTADO FEDERAL" if state=="MG" & name=="CARLOS DO CARMO ANDRADE MELLES"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="RJ" & name=="ALBERTO ELY BRIZOLA DA SILVA"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="SC" & name=="LUCI TERESINHA KOSWOSKI CHOINACKI"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="SC" & name=="ODACIR ZONTA"
replace office_elected1998="DEPUTADO ESTADUAL" if state=="TO" & name=="JOSINIANE BRAGA NUNES"
replace office_elected2000="VEREADOR" if state=="AL" & name=="JOSE CICERO SOARES DE ALMEIDA"
replace office_elected2000="VEREADOR" if state=="BA" & name=="ERONILDES VASCONCELOS CARVALHO"
replace office_elected2000="VEREADOR" if state=="BA" & name=="LUIZ CARLOS CAETANO"
replace office_elected2000="PREFEITO" if state=="BA" & name=="ROBERTO PEREIRA DE BRITTO"
replace office_elected2000="VEREADOR" if state=="CE" & name=="RONALDO MANCHADO MARTINS"
replace office_elected2000="VEREADOR" if state=="GO" & name=="MAURO RUBEM DE MENEZES JONAS"
replace office_elected2000="VEREADOR" if state=="MA" & name=="CLEBER VERDE CORDEIRO MENDES"
replace office_elected2000="VEREADOR" if state=="MG" & name=="JOSIAS DE AGUIAR RIBEIRO"
replace office_elected2000="VEREADOR" if state=="MG" & name=="MARIA DO SOCORRO JO MORAES"
replace office_elected2000="VEREADOR" if state=="MG" & name=="WELITON FERNANDES PRADO"
replace office_elected2000="VEREADOR" if state=="PA" & name=="DENISE TEREZINHA GABRIEL"
replace office_elected2000="VEREADOR" if state=="PA" & name=="JOAS POSSIDONIO ALVES MARTINS REIS"
replace office_elected2000="VEREADOR" if state=="PE" & name=="INALDO SATILINO DE OLIVEIRA"
replace office_elected2000="VEREADOR" if state=="PE" & name=="MOISES FRANCISCO DA SILVA"
replace office_elected2000="VEREADOR" if state=="RS" & name=="JONES ALEXANDRE MARTINS"
replace office_elected2000="VEREADOR" if state=="SC" & name=="ADILSON MARIANO"
replace office_elected2000="PREFEITO" if state=="SE" & name=="ANDRE LUIS DANTAS FERREIRA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="ADLER ALFREDO JARDIM TEIXEIRA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="FRANCISCO DOS REIS VILELA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="JAIRO DE SOUZA"
replace office_elected2000="VEREADOR" if state=="SP" & name=="MARCELO RICARDO MARIANO"
replace office_elected2000="VEREADOR" if state=="SP" & name=="ODMIR ALVES PEREIRA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="AM" & name=="ATILA SIDNEY LINS DE ALBUQUERQUE"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="AM" & name=="ERONILDO BRAGA BEZERRA"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="CE" & name=="RONALDO MANCHADO MARTINS"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="ES" & name=="GILSON ANTONIO DE SALES AMARO"
replace office_elected2002="DEPUTADO FEDERAL" if state=="MG" & name=="CARLOS DO CARMO ANDRADE MELLES"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MG" & name=="DOMINGOS SAVIO CAMPOS RESENDE"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MG" & name=="MARIA DO SOCORRO JO MORAES"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="MT" & name=="SAGUAS MORAES SOUSA"
replace office_elected2002="DEPUTADO ESTADUAL" if state=="PA" & name=="DENISE TEREZINHA GABRIEL"
replace office_elected2002="DEPUTADO FEDERAL" if state=="RJ" & name=="WANDERLEY ALVES DE OLIVEIRA"
replace office_elected2002="DEPUTADO FEDERAL" if state=="SC" & name=="CARLITO MERSS"
replace office_elected2002="DEPUTADO FEDERAL" if state=="SC" & name=="LUCI TERESINHA KOSWOSKI CHOINACKI"
replace office_elected2004="VEREADOR" if state=="AL" & name=="MARIA FATIMA GALINA FORTES FERREIRA SANTIAGO"
replace office_elected2004="PREFEITO" if state=="AP" & name=="EURICELIA MELO CARDOSO"
replace office_elected2004="VEREADOR" if state=="BA" & name=="ERONILDES VASCONCELOS CARVALHO"
replace office_elected2004="VEREADOR" if state=="BA" & name=="MILTON SANTOS GRAMACHO"
replace office_elected2004="PREFEITO" if state=="ES" & name=="GILSON ANTONIO DE SALES AMARO"
replace office_elected2004="VEREADOR" if state=="MA" & name=="CLEBER VERDE CORDEIRO MENDES"
replace office_elected2004="VEREADOR" if state=="PA" & name=="DENISE TEREZINHA GABRIEL"
replace office_elected2004="VEREADOR" if state=="PE" & name=="DANILO JORGE DE BARROS CABRAL"
replace office_elected2004="PREFEITO" if state=="RS" & name=="JORGE ALBERTO DUARTE GRILL"
replace office_elected2004="PREFEITO" if state=="SP" & name=="HERCULANO CASTILHO PASSOS JUNIOR"
replace office_elected2006="DEPUTADO FEDERAL" if state=="AM" & name=="ATILA SIDNEY LINS DE ALBUQUERQUE"
replace office_elected2006="DEPUTADO FEDERAL" if state=="BA" & name=="LUIZ ALBERTO SILVA DOS SANTOS"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="BA" & name=="RONALDO CARLETTO"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="GO" & name=="MAURO RUBEM DE MENEZES JONAS"
replace office_elected2006="DEPUTADO FEDERAL" if state=="MA" & name=="CLEBER VERDE CORDEIRO MENDES"
replace office_elected2006="DEPUTADO FEDERAL" if state=="MG" & name=="CARLOS DO CARMO ANDRADE MELLES"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="MG" & name=="MARIA DO SOCORRO JO MORAES"
replace office_elected2006="DEPUTADO ESTADUAL" if state=="SC" & name=="JORGINHO DOS SANTOS MELLO"
replace office_elected2006="EPUTADO ESTADUAL" if state=="SE" & name=="ANDRE LUIS DANTAS FERREIRA"
replace office_elected2008="PREFEITO" if state=="BA" & name=="ADALBERTO LELIS FILHO"
replace office_elected2008="VEREADOR" if state=="MG" & name=="ANDREIA MARTINS DE SOUZA BOTELHO"
replace office_elected2008="VEREADOR" if state=="MT" & name=="ROGERIO SILVA SANTOS"
replace office_elected2008="VEREADOR" if state=="PA" & name=="FAISAL FARIS MAHMOUD SALMEN HUSSAIN"
replace office_elected2008="VEREADOR" if state=="PA" & name=="JOAS POSSIDONIO ALVES MARTINS REIS"
replace office_elected2008="VEREADOR" if state=="PB" & name=="UBIRATAN PEREIRA DE OLIVEIRA"
replace office_elected2010="DEPUTADO FEDERAL" if state=="BA" & name=="SERGIO LUIS LACERDA BRITO"
replace office_elected2010="DEPUTADO FEDERAL" if state=="MA" & name=="JOSE ALBERTO OLIVEIRA VELOSO FILHO"
replace office_elected2010="DEPUTADO FEDERAL" if state=="MT" & name=="ROGERIO SILVA SANTOS"
replace office_elected2010="DEPUTADO FEDERAL" if state=="PA" & name=="JOSE ROBERTO OLIVEIRA FARO"
replace office_elected2010="DEPUTADO FEDERAL" if state=="RJ" & name=="CARLOS FREDERICO KOHLER"
replace office_elected2010="DEPUTADO FEDERAL" if state=="RJ" & name=="EDSON SANTOS DE SOUZA"
replace office_elected2012="VEREADOR" if state=="AL" & name=="MARIA FATIMA GALINA FORTES FERREIRA SANTIAGO"
replace office_elected2012="VEREADOR" if state=="MT" & name=="ROBERTO CARLOS DIONESIO LUCAS"
replace office_elected2012="PREFEITO" if state=="PA" & name=="ADOLF FREDERICO RETTELBUSCH"
replace office_elected2012="VEREADOR" if state=="PA" & name=="FAISAL FARIS MAHMOUD SALMEN HUSSAIN"

*Generate useful variables and code the missings zero
gen DE1998=0
replace DE1998=1 if office_elected1998=="DEPUTADO ESTADUAL"
gen DF1998=0
replace DF1998=1 if office_elected1998=="DEPUTADO FEDERAL"
gen PR2000=0
replace PR2000=1 if office_elected2000=="PREFEITO"
gen VE2000=0
replace VE2000=1 if office_elected2000=="VEREADOR"
gen DE2002=0
replace DE2002=1 if office_elected2002=="DEPUTADO ESTADUAL"
replace DE2002=1 if office_elected2002=="DEPUTADO DISTRITAL"
gen DF2002=0
replace DF2002=1 if office_elected2002=="DEPUTADO FEDERAL"
gen PR2004=0
replace PR2004=1 if office_elected2004=="PREFEITO"
gen VE2004=0
replace VE2004=1 if office_elected2004=="VEREADOR"
gen DE2006=0
replace DE2006=1 if office_elected2006=="DEPUTADO ESTADUAL"
replace DE2006=1 if office_elected2006=="DEPUTADO DISTRITAL"
gen DF2006=0
replace DF2006=1 if office_elected2006=="DEPUTADO FEDERAL"
gen PR2008=0
replace PR2008=1 if office_elected2008=="PREFEITO"
gen VE2008=0
replace VE2008=1 if office_elected2008=="VEREADOR"
gen DE2010=0
replace DE2010=1 if office_elected2010=="DEPUTADO ESTADUAL"
replace DE2010=1 if office_elected2010=="DEPUTADO DISTRITAL"
gen DF2010=0
replace DF2010=1 if office_elected2010=="DEPUTADO FEDERAL"
gen PR2012=0
replace PR2012=1 if office_elected2012=="PREFEITO"
gen VE2012=0
replace VE2012=1 if office_elected2012=="VEREADOR"
gen SE19982012=0
replace SE19982012=1 if office_elected1998=="SENADOR"
replace SE19982012=1 if office_elected2002=="SENADOR"
replace SE19982012=1 if office_elected2006=="SENADOR"
gen GO19982012=0
replace GO19982012=1 if office_elected1998=="GOVERNADOR"
replace GO19982012=1 if office_elected2002=="GOVERNADOR"
replace GO19982012=1 if office_elected2006=="GOVERNADOR"

*label variables
label variable DE1998 "State Deputy 1998"
label variable DE2002 "State Deputy 2002"
label variable DE2006 "State Deputy 2006"
label variable DE2010 "State Deputy 2010"
label variable DF1998 "Federal Deputy 1998"
label variable DF2002 "Federal Deputy 2002"
label variable DF2006 "Federal Deputy 2006"
label variable DF2010 "Federal Deputy 2010"
label variable PR2000 "Mayor 2000"
label variable PR2004 "Mayor 2004"
label variable PR2008 "Mayor 2008"
label variable PR2012 "Mayor 2012"
label variable VE2000 "Councilor 2000"
label variable VE2004 "Councilor 2004"
label variable VE2008 "Councilor 2008"
label variable VE2012 "Councilor 2012"
label variable SE19982012 "Senator 1998-2012"
label variable GO19982012 "Governor 1998-2012"
label variable office_elected1998 "Office elected into 1998"
label variable office_elected2000 "Office elected into 2000"
label variable office_elected2002 "Office elected into 2002"
label variable office_elected2004 "Office elected into 2004"
label variable office_elected2006 "Office elected into 2006"
label variable office_elected2008 "Office elected into 2008"
label variable office_elected2010 "Office elected into 2010"
label variable office_elected2012 "Office elected into 2012"

*drop variables that are not used for analysis
drop dupl_06_08_10_12 dupl00 state_name_dupl state_shortname_dupl _merge

save Brazil_candidates.dta, replace

*Continue with Brazil_candidates_replication_candidates_analysis.do


***********Validation: Comparison of random sample with third sources***********

*Randomly select 30 cases
set seed 229394
sample 30, count

*List the random sample with info on incumbency
list state name office_elected1998 office_elected2000 office_elected2002 /*
*/office_elected2004 office_elected2006  office_elected2008 office_elected2010 /*
*/office_elected2012

/*Google the names and state names and screen first 20 entries on information about
political offices. In particular check electoral results.
1) No offices, no information about previous offices found => correct
2) No offices, no information about previous offices found => correct
3) No offices, no information about previous offices found => correct
4) Vereador in 2000, no information about previous office found => correct/false positive
5) Vereador 2008 and 2012, fits information here https://cnpj.biz/16276682000108 and 
here https://bahiaja.com.br/politica/noticia/2010/06/14/vereador-de-casa-nova-se-queixa-do-psdb-por-lhe-ter-negado-legenda,25337,0.html
=> correct
6) No offices, no information about offices from 1998 on found => correct
7) No offices, no information about previous offices found => correct
8) No offices, no information about previous offices found => correct
9) Vereador 2008 and 2012, information on the election into the offices found
here https://www.tre-rj.jus.br/site/eleicoes/2008/resultados/eleitos/mage.pdf and
here: https://pt.wikipedia.org/wiki/Lista_de_vereadores_de_Mag%C3%A9
=> correct
10) Vereador in 2000 and 2012, information found here 
https://www.folhadelondrina.com.br/politica/manobra-causa-confusao-na-camara-de-colombo-386396.html
and here https://www.jornalolhonolance.com.br/2019/05/vereadores-e-servidores-da-camara.html
=> correct
11) No offices, no information about previous offices found => correct
12) No offices, no information about previous offices found => correct
13) No offices, no information about previous offices found => correct
14) No offices, no information about previous offices found => correct
15) No offices, no information about previous offices found => correct
16) No offices, no information about previous offices found => correct
17) Vereador 2008, no information about previous offices found => correct/false positive
18) No offices, no information about previous offices found => correct
19) No offices, no information about previous offices found => correct
20) No offices, information fully consistent: http://produtos.seade.gov.br/produtos/eleicoes/candidatos/index.php?page=pol_det&cand=33404
=> correct
21) No offices, no information about previous offices found => correct
22) No offices, no information about previous offices found => correct
23) No offices, no information about previous offices found => correct
24) No offices, no information about previous offices found => correct
25) No offices, no information about previous offices found => correct
26) Vereador 2000, 2004, 2008, 2012, information consistent with this: http://www.camaravarzeagrande.mt.gov.br/site/perfil_vereador/11
=> correct
27) Vereador 2012, information conistent with this: http://cmbr.rj.gov.br/?page_id=244
28) Verador 2008 and 2012, consistent with personal biography: http://marcelooliveira.com.br/Biografia
29) No offices, no information about previous offices found => correct
30) Vereador 2008 and 2012, vereador 2012 consistent with: https://www.cmdc.rj.gov.br/?attachment_id=3070
no information on first term. => correct/false positive





